package com.blog.attach.controller;


import com.blog.attach.service.UserReplayService;
import com.blog.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 苏离
 * @since 2022-01-18
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/attach/userReplay")
public class UserReplayController {
@Autowired
    UserReplayService replayService;

@GetMapping("/getReplay/{parentId}/{pageNo}/{limit}")
    public ResponseResult getReplayByParentId(@PathVariable Integer limit,
                                              @PathVariable Integer pageNo,
                                              @PathVariable Integer parentId){
    Map<String, Object> replays = replayService.getReplays(parentId, pageNo, limit);
    return ResponseResult.ok().data(replays);
}

    @PostMapping("/getReplay/{userId}/{BeUserId}/{parentId}")
    public ResponseResult insertReplay(@PathVariable String BeUserId,
                                       @PathVariable Integer parentId,
                                       @PathVariable String userId,
                                       @RequestBody Map<String,String> map){
        String replayContent = map.get("replayContent");
        if(replayService.insertReplay(userId, BeUserId, parentId,replayContent))
        return ResponseResult.ok().message("回复成功");
        return ResponseResult.error().message("回复失败");
    }
}

